//
//  AlwayViewController.m
//  ICup
//
//  Created by liao Echo on 14-10-12.
//  Copyright (c) 2014年 Echo. All rights reserved.
//

#import "AlwayViewController.h"
#import "HistoryTableViewController.h"
#import "CircularProgressView.h"
#import "singlePeripheral.h"


@interface AlwayViewController (){
    CircularProgressView *circularProgressView;
}

@end

@implementation AlwayViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)rightPressed{
    HistoryTableViewController *view = [[HistoryTableViewController alloc] init];
    [self.navigationController pushViewController:view animated:YES];
}
- (void)viewDidLoad
{
    self.title = @"习惯";
    
    [super viewDidLoad];
    float measure = [[singlePeripheral instance] getTodayWaterMeasure];
    
    
    UIButton *btnView = [UIButton buttonWithType:UIButtonTypeCustom];
    btnView.frame = CGRectMake(0, 0, 44, 44);
    [btnView setImage:IMG(@"右上边  按键-曲线.png") forState:UIControlStateNormal];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnView];
    [btnView addTarget:self action:@selector(rightPressed) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = barButtonItem;
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"历史纪录" style:UIBarButtonItemStyleBordered target:self action:@selector(rightPressed)];
    
    circularProgressView = [[CircularProgressView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-343/2)/2, 5, 343/2, 343/2)];
    circularProgressView.userInteractionEnabled = NO;
    circularProgressView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:circularProgressView];
    circularProgressView.backColor = [UIColor colorWithRed:34 / 255.0
                                                     green:41 / 255.0
                                                      blue:51 / 255.0
                                                     alpha:1.0];
    circularProgressView.progressColor = [UIColor colorWithRed:195 / 255.0
                                                         green:191 / 255.0
                                                          blue:190 / 255.0
                                                         alpha:1.0];
    
    
    circularProgressView.lineWidth = 5;
    
    [circularProgressView updateProgressCircle:.5];
    
    label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 35, SCREEN_WIDTH, 100)];
    label1.textColor = [UIColor whiteColor];
    label1.textAlignment = UITextAlignmentCenter;
    label1.font = [UIFont systemFontOfSize:80];
    label1.backgroundColor = [UIColor clearColor];
    [self.view addSubview:label1];
    
    label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 40+FY(label1), SCREEN_WIDTH, 100)];
    label2.textColor = [UIColor whiteColor];
    label2.textAlignment = UITextAlignmentCenter;
    label2.font = [UIFont systemFontOfSize:15];
    label2.backgroundColor = [UIColor clearColor];
    [self.view addSubview:label2];
    
    
    label2.text = @"分";
    
    label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-438/2-64, SCREEN_WIDTH, 50)];
    label3.textColor = RGB(37, 190, 187, 1);
    label3.textAlignment = UITextAlignmentCenter;
    label3.font = [UIFont systemFontOfSize:17];
    label3.backgroundColor = [UIColor blackColor];
    [self.view addSubview:label3];
    label3.text = @"多喝点水，对身体大有好处哦！";
    
    UIView *VIEW = [[UIView alloc] initWithFrame:CGRectMake(0, FY(label3)+FH(label3), SCREEN_WIDTH, 180/2)];
    VIEW.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:VIEW];
    
    for (int i=0; i<2; i++) {
        UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(0, 32, SCREEN_WIDTH, 1)];
        if (i == 1) {
            subview.frame = CGRectMake(SCREEN_WIDTH/2, 0, 1, FH(VIEW));
        }
        subview.backgroundColor = [UIColor grayColor];
        [VIEW addSubview:subview];
    }
    
    for (int i=0; i<5; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/2, 65/2)];
        label.textColor = RGB(67, 76, 87, 1);
        label.textAlignment = UITextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:17];
        label.backgroundColor = [UIColor clearColor];
        [VIEW addSubview:label];
        
        if (i == 0) {
            label4 = label;
        }else if (i == 1) {
            label.frame = CGRectMake(0, 65/2+5, SCREEN_WIDTH/2, 65/2);
            label.textColor = RGB(109, 109, 109, 1);
            label5 = label;
        }else if (i == 2) {
            label.frame = CGRectMake(SCREEN_WIDTH/2, 65/2+5, SCREEN_WIDTH/2, 65/2);
            label.textColor = RGB(109, 109, 109, 1);
            label6 = label;
        }else if (i == 3) {
            label.frame = CGRectMake(0, 65/2+25, SCREEN_WIDTH/2, 65/2);
            label7 = label;
        }else if (i == 4) {
            label.frame = CGRectMake(SCREEN_WIDTH/2, 65/2+25, SCREEN_WIDTH/2, 65/2);
            label8 = label;
        }
        
    }
    
//    int star = 3;
//    for (int i=0; i<5; i++) {
//        UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+i*20+30, (65/2.0-16)/2.0, 17, 16)];
//        imageview.image = IMG(@"五角星--橙色.png");
//        if (i+1>star) {
//            imageview.image = IMG(@"五角星- 白色-.png");
//        }
//        [VIEW addSubview:imageview];
//    }
    
    
//    label4.text = @"三星级达人";
    label5.text = @"日饮水量";
    label6.text = @"饮水习惯评分";
    label7.text = @"0 ml";
    
    label7.text = [NSString stringWithFormat:@"%d", (int)measure*5];
    
    
    UIButton *AdView = [[UIButton alloc] initWithFrame:RECT(10, SCREEN_HEIGHT-138/2-64, 300, 44)];
    [AdView setTitle:@"评价我的习惯" forState:UIControlStateNormal];
    [AdView setBackgroundImage:IMG(@"按键-底色0.png") forState:UIControlStateNormal];
//    [AdView addTarget:self action:@selector(AdViewPressed) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:AdView];
    
    
    [self setScore:[singlePeripheral getSroce:measure]];
}
-(void)setScore:(NSInteger)score{
    [circularProgressView updateProgressCircle:score/100.0];
    label1.text = [NSString stringWithFormat:@"%d", score];
    label8.text = [NSString stringWithFormat:@"%d 分", score];
}

@end








